package cn.tedu.micro.demo.all.dao.repository;

import cn.tedu.micro.demo.all.dao.mapper.StockMapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Wrapper;

@Repository
public class StockRepositoryImpl implements StockRepository{
    @Autowired
    private StockMapper stockMapper;
    @Override
    public int reduceCount(String productCode, Integer count) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("product_code",productCode);
        updateWrapper.setSql("stock = stock - "+count);
        return stockMapper.update(null,updateWrapper);
    }
}
